<include file="__THEME__/headerbase" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>
<script type="text/javascript" src="{:U('weibo/plugins/init')}"></script>
<script type="text/javascript" src="__PUBLIC__/js/Plugins/jquery.autocomplete.js"></script>
<link href="../Public/index.css" rel="stylesheet" type="text/css" />
<script>
$(document).ready(function(){
	weibo.init();
})

function close_announcement() {
	$('#announcement').hide('slow');
	$.post("{:U('home/User/closeAnnouncement')}",{},function(res){});
}
</script>
<!-- 内容 begin  --> 
      <div style="overflow:hidden;">
        <php>if($announcement['is_open'] && !empty($announcement['content'])) {</php>
        <div class="iine_warning" style="padding: 5px; *display: inline-block" id="announcement"><a class="del right" href="javascript:void(0);" onclick="close_announcement();"></a>{$announcement['content']}</div>
        <php>}</php>
        <div class="talkBox">
          <form method="post" action="{:U('weibo/operate/publish')}" id="miniblog_publish" oncomplete="false">
            <input type="hidden" name="publish_type" value="0">
            <h2>
              <div class="wordNum">你还可以输入<strong id="strconunt">140</strong>字</div>
              <span>快来说点什么吧……</span></h2>
            <div class="cntBox">
              <textarea name="content" id="content_publish" class="content_publish" cols="" rows=""style="width:99.3%;_width:99%; height:78px;padding:5px 0;"></textarea>
              <div class="txtShadow" style="z-index:-1000"></div>
            </div>
            <div class="funBox">
              <div class="right" style="padding-bottom:5px;"> 同步到:
                <input type="checkbox" name="sync[]" value="sina" id="sina_sync" <php>if($login_bind['sina']){</php>checked<php>}</php> onclick="selectSync(this)">
                <img src="../Public/images/sina.png" align="absmiddle">				
				
                <input type="checkbox" name="sync[]" value="qq" id="qq_sync" <php>if($login_bind['qq']){</php>checked<php>}</php> onclick="selectSync(this)">
                <img src="../Public/images/qq.png" align="absmiddle">

				<input type="checkbox" name="sync[]" value="twitter" id="twitter_sync" <php>if($login_bind['twitter']){</php>checked<php>}</php> onclick="selectSync(this)">
                <img src="../Public/images/twitter.png" align="absmiddle">

                <input type="checkbox" name="sync[]" value="facebook" id="facebook_sync" <php>if($login_bind['facebook']){</php>checked<php>}</php> onclick="selectSync(this)">
                <img src="../Public/images/facebook.png" align="absmiddle">

                <input type="button" disabled="true" onclick="weibo.do_publish()" class="btn_big_disable hand" value="&nbsp;" id="publish_handle"  />
              </div>
              <div id="publish_type_content_before" class="left">  </div>
            </div>
          </form>
        </div>
        </div>
<!-- 内容 end --> 
<script>
	<php>if(ACTION_NAME=='index' && $show_feed==0){</php>
	var sinceId = '{$vo.id}';
	var lastId  = '<php>echo $list["data"][0]["id"]</php>';
	var showfeed = '{$show_feed}';
	<php>}</php>
$(document).ready(function(){
	//微博字数控制
<php>if($type=='' && ACTION_NAME=='index' && $show_feed==0){</php>
	//更新最新的微博数
	setInterval("countNew()",120000);
<php>}</php>
});



//添加关注话题
function addFollowTopic(){
	var name = $("input[name='quick_name']").val();
	if(name==''){
		alert('请输入话题名称');
		return false;
	}
	$.post(U('weibo/operate/followtopic'),{name:name},function(txt){
		if(txt=='12'){
			$("input[name='quick_name']").val('');
			$('.quick_win').hide();
			$("ul[rel='followTopicArea']").append('<li><a class="ico_close right" title="删除" href="javascript:void(0)" onclick="deleteFollowTopic(this,\''+name+'\')">x</a><a href="'+U('home/user/search',['k='+name])+'">'+name+'</a></li>');	
		}else if(txt=='11'){
			alert('已关注过此话题');
		}else{
			alert('关注失败');
		}

	});
}

//同步设置
function selectSync(o){
	if( o.checked ){
		$(o).removeAttr('checked');
		$.get( U('weibo/Operate/beforeSync') ,{type:$(o).val()},function(txt){
			if(txt=='1'){
				$(o).attr('checked','true');
			}else{
				ui.box.show(txt,{title:'绑定帐号'});
			}
		});		
	}else{
		$(o).attr('checked',true);
		$.post( U('weibo/operate/unbind') ,{value:$(o).val()},function(txt){
			$(o).removeAttr('checked');
		});	
	} 
}

//删除关注
function deleteFollowTopic(o,key){
	$.post(U('weibo/operate/unfollowtopic'),{name:key},function(txt){
		$(o).parents("li").remove();
	});
}

//获取未读取的条数
function countNew(){
	$.post(U('weibo/index/countnew'),{lastId:lastId,showfeed:showfeed},function(txt){
		if(txt.indexOf('<TSAJAX>')==0) {
			if(txt.indexOf('<HASNEW>')!=-1) {
				$('#countNew').html(txt);
			}
		}else{
			location.reload();
		}
	})
}

//加载未读取的微博
function loadNew(pLastId,limit,showfeed){
	$.post(U('weibo/index/loadnew'),{since:pLastId,limit:limit,showfeed:showfeed},function(txt){
		if(txt.indexOf('<TSAJAX>')==0){
			if(txt.indexOf('<HASNEW>')!=-1) {
	            lastId = pLastId;
	            $('#countNew').html('');
	            $('.feed_list').prepend(txt);
			}
		}else{
			location.reload();
		}
			
	})
}

//加载更多
function loadmore(o){
	var type = '{$type}';
	$(o).html('加载中...');
	$.post(U('weibo/index/loadmore'),{type:type,since:sinceId,showfeed:showfeed},function(txt){
		if(txt){
			$('.feed_list').append(txt);
		}
		$(o).html('更多');
		
	})
}


//更改动态显示
function changeFeedShowStatus(o){
		var Days = 30;  
	    var exp  = new Date();  
	    exp.setTime(exp.getTime() + Days*24*60*60*1000);	
	if( o.checked ){
	    document.cookie = "feed=1;expires=" + exp.toGMTString(); 
		location.reload();
	}else{
		document.cookie = "feed=0;expires=" + exp.toGMTString(); 
		location.reload();
	}
}

function deleteMini(id) {
	$.post(U('home/User/doDeleteMini'),{id:id},function(txt){
		if(txt == '1') {
			$("#list_li_"+id).slideUp('fast');
		}else {
			ui.error('删除失败，请稍后重试');
		}
	});
}

function setSearchUser(txt){
		alert(txt);
		reg = /@[^@\s]{1,20}$/g
		var   patt   =   new   RegExp(reg);
		var result = patt.exec( txt.val() );
		if(!result) return false;
		var textArea = document.getElementById('content_publish');
		var key = result.toString().replace('@','');

		$(".txtShadow").html('@' + '<span id="showTips"></span>');
		var p = $("#showTips").offset();
				$('#searchUser').css({
					top: p.top + 5,
					left: p.left
				});
		$('#searchUser').find('dl').html('<dt>你想用@提到谁？</dt><dt>test</dt>');
		$('#searchUser').show();
				
		/**
		$.get( U('weibo/Index/searchuser',['n='+key]),function(txt){
			if (txt!='null') {
				txt = eval("(" + txt + ")");
				var html = '';
				$.each(txt, function(i, n){
					html += '<dt>' + n.uname + '</dt>';
				});
				$(".txtShadow").html('@' + '<span id="showTips"></span>');
				var p = $("#showTips").offset();
				$('#searchUser').css({
					top: p.top + 5,
					left: p.left
				});
				$('#searchUser').find('dl').html('<dt>你想用@提到谁？</dt>' + html);
				$('#searchUser').show();
			}
		});
		**/
			
		//$('#searchUser').hide();
}
</script> 
